﻿param($computersListPath)

Import-Module ActiveDirectory


workflow Collect-OfficeTelemetry
{
    
    if($computersListPath -ne $null)
    {
        $computers=Get-Content -Path $computersListPath
    }
    else
    {
        $computers=(Get-ADComputer -LDAPFilter "(name=*)" -SearchBase "OU=Client Computers,dc=etfsinc,dc=com").Name
    }
    
    foreach -Parallel ($computer in $computers)
    {
        if($computer -inotlike "*v-*")
        {
            $connectionTest=Test-Connection -Count 1 -ComputerName $computer -ErrorAction SilentlyContinue
            if($connectionTest)
            {
                Write-Output "Starting Office Telemetry Collection on $computer"
                schtasks /TN Microsoft\Office\OfficeTelemetryAgentLogOn /run /s $computer

            }
            else
            {
                Write-Output "Cannot reach $computer"
            }
        }
        else
        {
            Write-Output "$computer is a service name,skipping."
        }
    }
}

Collect-OfficeTelemetry






















param($computers,$computersListFilePath)

if($computers -eq $null -and $computersListFilePath -ne $null)
{
    $computers=Get-Content $computersListFilePath
}

$totalComputers=$computers.Count
$monitoredComputers=0

foreach($computer in $computers)
{
    $computerName=$computer.Replace(" ","")

    if(Test-Connection -ComputerName $computerName -Count 1 -ErrorAction SilentlyContinue)
    {
        Write-Host "Starting services on "$computerName
        schtasks /TN Microsoft\Office\OfficeTelemetryAgentLogOn /run /s $computerName
        $monitoredComputers++
    }
    else
    {
        Write-Host "$computerName is not pinging, skipping."
    }
}

Write-Host "$monitoredComputers computers monitored on $totalComputers"
